package com.cheung.leetcode.dp;

import org.junit.jupiter.api.Test;

public class Code70Test {

    public int climbStairs(int n) {
        // 每次爬1或2步
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }

        // 第n阶楼梯的爬法==第n-1阶(再爬1步)+第n-2阶(再爬2步)
        int a = 1, b = 2;
        for (int i = 3; i <= n; i++) {
            int c = a + b;
            a = b;
            b = c;
        }

        return b;
    }

    @Test
    public void test1() {
        assert 2 == climbStairs(2);
    }

    @Test
    public void test2() {
        assert 3 == climbStairs(3);
    }
}
